package controllers.jobs;

import models.BaseModel;
import models.admin.AdminUser;
import play.Logger;
import play.jobs.Job;
import play.jobs.OnApplicationStart;

/**
 * Created by youliangcheng on 17/6/14.
 */
@OnApplicationStart
public class BootstrapBasicData extends Job {

    public void doJob() {

        Logger.info("开始预加载 数据模块...");
        createBasicData();
    }
    private static void createBasicData(){
        long userNumber = AdminUser.count();
        if(userNumber == 0){

            Logger.info("#生成部门管理根节点");
            BaseModel.execNativeSql("insert into admin_dept (code,name,parent_id,is_leaf,node_id_path,show_order,remark,deleted,create_at) values('BM0001','总公司',0,1,'/1/',0,'',0,now());");


            Logger.info("#初始化业务操作");

            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (1,'load','查询');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (2,'save','保存');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (3,'delete','删除');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (4,'index','首页');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (5,'add','新增页');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (6,'modify','详情页');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (7,'create','新建');");
            BaseModel.execNativeSql("insert into admin_operate (id,filterKey,name) values (8,'update','修改');");


            Logger.info("#主业务");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (1,now(),'COMM','BS0001','/power/admin/AdminBusinessCtrl','业务管理',0,'/power/admin/AdminBusinessCtrl/loadList?menuId=1','FREEZE',5,'AdminBusiness','BS',0 ,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (2,now(),'COMM','BS0002','/power/admin/AdminMenuCtrl','菜单管理',0,'/power/admin/AdminMenuCtrl/loadMenuList?menuId=2','FREEZE',1,'AdminMenu','CD',0 ,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (3,now(),'COMM','BS0003','/power/admin/AdminRoleCtrl','角色管理',0,'/power/admin/AdminRoleCtrl/loadRoleList?menuId=3','FREEZE',1,'AdminRole','JS',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (4,now(),'COMM','BS0004','/power/admin/AdminDeptCtrl','部门管理',0,'/power/admin/AdminDeptCtrl/adminDeptList?menuId=4','FREEZE',1,'AdminDept','BM',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (5,now(),'COMM','BS0005','/power/admin/AdminUserCtrl','用户管理',0,'/power/admin/AdminUserCtrl/loadUserList?menuId=5','FREEZE',1,'AdminUser','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (6,now(),'COMM','BS0006','/BS0006/admin/weixin/index','微信管理',0,'/BS0006/admin/weixin/index','FREEZE',1,'AdminUser','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (7,now(),'COMM','BS0007','/BS0007/admin/merchant/index','场馆管理',0,'/BS0007/admin/merchant/index','FREEZE',1,'AdminUser','',0,0);");

            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (8,now(),'COMM','BS0008','/BS0008/admin/webuser/index','会员管理',0,'/BS0008/admin/webuser/index?menuId=8','FREEZE',1,'WebUser','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (9,now(),'COMM','BS0009','/BS0009/admin/room/index','包房管理',0,'/BS0009/admin/room/index?menuId=9','FREEZE',1,'Room','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (10,now(),'COMM','BS00010','/BS0010/admin/room/plane','平面列表',0,'/BS0010/admin/room/plane?menuId=10','FREEZE',1,'Room','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (11,now(),'COMM','BS00011','/BS0011/admin/room/policy/index','价格设置',0,'/BS0011/admin/room/policy/index?menuId=11','FREEZE',1,'Room','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (12,now(),'COMM','BS00012','/BS0012/admin/room/book','线下预约',0,'/BS0012/admin/room/book?menuId=12','FREEZE',1,'Room','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (13,now(),'COMM','BS00013','/BS0013/admin/fitness/index','健身类型',0,'/BS0013/admin/fitness/index?menuId=13','FREEZE',1,'fitness','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (14,now(),'COMM','BS00014','/BS0014/admin/coach/index','私教管理',0,'/BS0014/admin/coach/index?menuId=14','FREEZE',1,'Coach','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (15,now(),'COMM','BS00015','/BS0015/admin/curriculumType/index','课程类型管理',0,'/BS0015/admin/curriculumType/index?menuId=15','FREEZE',1,'CurriculumType','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (16,now(),'COMM','BS00016','/BS0016/admin/curriculum/index','课程管理',0,'/BS0016/admin/curriculum/index?menuId=16','FREEZE',1,'Curriculum','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (17,now(),'COMM','BS00017','/BS0017/admin/order/index','订单管理',0,'/BS0017/admin/order/index?menuId=17','FREEZE',1,'Order','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (18,now(),'COMM','BS00018','/BS0018/admin/product/type/index','产品类型管理',0,'/BS0018/admin/product/type/index?menuId=18','FREEZE',1,'ProductType','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (19,now(),'COMM','BS00019','/BS0019/admin/product/index','产品管理',0,'/BS0019/admin/product/index?menuId=19','FREEZE',1,'Product','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (20,now(),'COMM','BS00020','/BS0020/admin/seat/index','桌位管理',0,'/BS0020/admin/seat/index?menuId=20','FREEZE',1,'Seat','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (21,now(),'COMM','BS00021','/manage/recharge/RechargeComboCtrl','充值套餐管理',0,'/manage/recharge/RechargeComboCtrl/rechargeComboList?menuId=21','FREEZE',1,'RechargeCombo','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (22,now(),'COMM','BS00022','/BS0022/admin/recharge/index','会员卡充值',0,'/BS0022/admin/recharge/index?menuId=22','FREEZE',1,'recharge','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (23,now(),'COMM','BS00023','/BS0023/admin/order/index/PRODUCT/TRUE','水吧订单管理',0,'/BS0023/admin/order/index/PRODUCT/TRUE?menuId=23','FREEZE',1,'Order','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (24,now(),'COMM','BS00024','/BS0024/admin/report/source/index','订单来源分析',0,'/BS0024/admin/report/source/index?menuId=24','FREEZE',1,'source','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (25,now(),'COMM','BS00025','/BS0025/admin/report/paytype/index','订单支付类型分析',0,'/BS0025/admin/report/paytype/index?menuId=25','FREEZE',1,'paytype','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (26,now(),'COMM','BS00026','/BS0026/admin/report/trend/index','日订单趋势',0,'/BS0026/admin/report/trend/index?menuId=26','FREEZE',1,'trend','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (27,now(),'COMM','BS00027','/BS0027/admin/policy/index?menuId=27','健身收费管理',0,'/BS0027/admin/policy/index?menuId=27','FREEZE',1,'policy','',0,0);");
            BaseModel.execNativeSql("insert into admin_business (id,create_at,business_type,code,controller,name,show_order,url,code_date_available,code_num,main_entity,prefix,version,deleted) values (28,now(),'COMM','BS00028','/manage/orderSource/OrderSourceCtrl','第三方管理',0,'/manage/orderSource/OrderSourceCtrl/loadList?menuId=28','FREEZE',1,'OrderSource','',0,0);");

            Logger.info("#主业务操作");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (1,'load','查询','SYSTEM',1);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (2,'save','保存','SYSTEM',1);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (3,'delete','删除','SYSTEM',1);");

            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (4,'load','查询','SYSTEM',2);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (5,'save','保存','SYSTEM',2);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (6,'delete','删除','SYSTEM',2);");

            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (7,'load','查询','SYSTEM',3);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (8,'save','保存','SYSTEM',3);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (9,'delete','删除','SYSTEM',3);");

            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (10,'load','查询','SYSTEM',4);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (11,'save','保存','SYSTEM',4);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (12,'delete','删除','SYSTEM',4);");

            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (13,'load','查询','SYSTEM',5);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (14,'save','保存','SYSTEM',5);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (15,'delete','删除','SYSTEM',5);");
//            #微信管理操作
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (16,'index','首页','SYSTEM',6);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (17,'add','新增页','SYSTEM',6);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (18,'modify','详情页','SYSTEM',6);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (19,'create','新建','SYSTEM',6);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (20,'update','修改','SYSTEM',6);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (21,'delete','删除','SYSTEM',6);");

//            #场馆管理操作
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (22,'index','首页','SYSTEM',7);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (23,'add','新增页','SYSTEM',7);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (24,'modify','详情页','SYSTEM',7);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (25,'create','新建','SYSTEM',7);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (26,'update','修改','SYSTEM',7);");
            BaseModel.execNativeSql("insert into admin_business_operate (id,filterKey,name,operate_type,business_id) values (27,'delete','删除','SYSTEM',7);");

            Logger.info("#菜单");
            BaseModel.execNativeSql("insert into admin_menu (id,create_at,code,name,available_status) values (1,now(),'CD0001','管理员级菜单','AVAILABLE');");

            Logger.info("#菜单明细");


            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(1,now(),0,1,'系统管理',0,0,null);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(2,now(),1,1,'业务管理',1,1,1);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(3,now(),1,1,'菜单管理',1,2,2);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(4,now(),1,1,'角色管理',1,3,3);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(5,now(),1,1,'部门管理',1,4,4);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(6,now(),1,1,'用户管理',1,5,5);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(7,now(),1,1,'微信管理',0,1,6);");
            BaseModel.execNativeSql("insert into admin_menu_item (id,create_at,is_leaf,menu_id,name,parent_id,show_order,business_id) values(8,now(),1,1,'场馆管理',0,2,7);");

            Logger.info("#角色");
            BaseModel.execNativeSql("insert into admin_role (id,create_at,code,menu_id,name,available_status) values(1,now(),'JS0001',1,'超级管理员','AVAILABLE');");

            Logger.info("#角色权限");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(1,now(),1,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(2,now(),2,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(3,now(),3,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(4,now(),4,1);");

            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(5,now(),5,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(6,now(),6,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(7,now(),7,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(8,now(),8,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(9,now(),9,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(10,now(),10,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(11,now(),11,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(12,now(),12,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(13,now(),13,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(14,now(),14,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(15,now(),15,1);");

//            #微信管理权限
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(16,now(),16,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(17,now(),17,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(18,now(),18,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(19,now(),19,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(20,now(),20,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(21,now(),21,1);");

//            #场馆管理权限
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(22,now(),22,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(23,now(),23,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(24,now(),24,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(25,now(),25,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(26,now(),26,1);");
            BaseModel.execNativeSql("insert into admin_role_operate(id,create_at,admin_biz_operate_id,admin_role_id) values(27,now(),27,1);");


            Logger.info("##微信管理");
            BaseModel.execNativeSql("insert into weixin_datas(id,create_at,deleted , name) values(1,now(),0 , '首个微信信息');");

            Logger.info("##场馆管理");
            BaseModel.execNativeSql("insert into power_merchants(id,create_at,deleted , weixin_datas_id ,link_id , name ) values(1,now(),0 , 1 , 1 , '场馆');");


            Logger.info("#用户管理");
            BaseModel.execNativeSql("insert into admin_user(id,create_at,available_status,deleted,login_name,name,password,phone_no,admin_dept_id,admin_user_auth,admin_user_type ,merchant_id) values(1,now(),'AVAILABLE',0,'admin','超级管理员','ISMvKXpXpadDiUoOSoAfww==','15006333020',1,'DEPT','NORMAL' , 1);");

            Logger.info("#用户角色");
            BaseModel.execNativeSql("insert into admin_user_role(id,admin_role_id,admin_user_id) values(1,1,1);");




        }else {
            Logger.info("-------------初始数据已存在-------------");
        }
    }

}
